Fix memory leaks in tests case.c and misc.c (#189)
authorAndreas-Schniertshauer <59561559+Andreas-Schniertshauer@users.noreply.github.com>
Mon, 30 Mar 2020 11:51:44 +0000 (13:51 +0200)
committerGitHub <noreply@github.com>
Mon, 30 Mar 2020 11:51:44 +0000 (07:51 -0400)
* Add: tests to CMakeLists.txt

* Disable compilation of charwidth, graphemetest and normtest because of missing getline

* Refactoring: UTF8PROC_ENABLE_TESTING default Off, move tests that don't compile on windows to NOT MSVC section, add testing to appveyor.yml

* Add: testing to travis

* Changed: flag to WIN32 because MinGW has the same problem as MSVC

* Commented out graphemetest and normtest because they fail.

* Re-added: graphemetest and normtest added missing data to the path of the text files.

* Fix: last commit was party wrong normtest failed.

* * Commented out graphemetest and normtest because they fail, because in CMakeLists is missing building of data.

* Add: mingw_static, mingw_shared, msvc_shared, msvc_static to ignore list

* Add: prefix utf8proc. to tests

* Fix: memory leaks in tests case.c and misc.c forgot to call free after calling utf8proc_NFKC_Casefold

Co-authored-by: Andreas-Schniertshauer <Andreas-Schniertshauer@users.noreply.github.com>
test/case.c
test/misc.c

index b3947e2ad5f3bbc64ae3f9b2295682518472346b..4a98a6390b52ead10cdb69a0d4de1cb03657f7ec 100644 (file)
@@ -63,10 +63,13 @@ int main(int argc, char **argv)
            "incorrect 0x00df/0x1e9e case conversions");
      utf8proc_uint8_t str_00df[] = {0xc3, 0x9f, 0x00};
      utf8proc_uint8_t str_1e9e[] = {0xe1, 0xba, 0x9e, 0x00};
-     check(!strcmp((char*)utf8proc_NFKC_Casefold(str_00df), "ss") &&
-           !strcmp((char*)utf8proc_NFKC_Casefold(str_1e9e), "ss"),
+     utf8proc_uint8_t *s1 = utf8proc_NFKC_Casefold(str_00df);
+     utf8proc_uint8_t *s2 = utf8proc_NFKC_Casefold(str_1e9e);
+     check(!strcmp((char*)s1, "ss") &&
+           !strcmp((char*)s2, "ss"),
            "incorrect 0x00df/0x1e9e casefold normalization");
-
+     free(s1);
+     free(s2);
      printf("More up-to-date than OS unicode tables for %d tests.\n", better);
      printf("utf8proc case conversion tests SUCCEEDED.\n");
      return 0;
index 8655233b05775d4ce7b9377ea4e9bd402580492a..9156f95541d40e9d5f81e4a085980b31034d078b 100644 (file)
@@ -35,6 +35,7 @@ static void issue102(void) /* #128 */
     printf("NFKC_Casefold \"%s\" -> \"%s\" vs. \"%s\"\n", (char*)input, (char*)output, (char*)correct);
     check(strlen((char*) output) == 7, "incorrect NFKC_Casefold length");
     check(!memcmp(correct, output, 8), "incorrect NFKC_Casefold data");
+    free(output);
 }
 
 int main(void)